class Admin::ProfileController < ApplicationController
  layout "admin/users"
  before_filter :protect, :except => [:gain_cities,:gain_areas]
  
  def vip_register
    @title = "升级为vip用户"
    @scripts = ["jquery.validate.min.js","fendu/fendu_vip.js"]
    @login_user = User.find(session[:user_id])
    @profile = Profile.new(params[:profile])
    if @login_user.is_vip==NO && param_posted?(:profile)
      pro_vip_register(@login_user,@profile)
    end
  end
  
  def audit
    @title = "网站审核"
    @user = User.find(session[:user_id])
  end
  
  def gain_cities
    @cities = City.find( :all, :conditions => ['pid = ?', params[:province_id]] )
    render :partial => "city_select", :layout => false
  end
  
  def gain_areas
    @areas = Area.find( :all, :conditions => ['pid = ?', params[:city_id]] )
    render :partial => "area_select", :layout => false
  end
  
  private 
  def pro_vip_register(user,profile)
    profile.check_name_and_company(user)
    if profile.duplicate? or profile.save
      user.profile = profile
      redirect_to :action => :audit
    end
  end
end
